<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //补全字符串长度
    console.log('x'.padStart(5,'ab'));
    console.log('x'.padEnd(5,'ab'));
    console.log('x'.padEnd(4,'ab'));
    //源字符串的长度，等于或大于最大长度，不会消减原字符串，返回原字符串
    //用来补全的字符串与原字符串长度之和超过了最大长度，截取超出位数的补全字符串，原字符串不动
    console.log('abc'.padStart(10,'0123456789'));
    console.log('abc'.padEnd(10,'0123456789'));
    //省略第二个参数，默认使用空格补全长度
    console.log('x'.padStart(4));
    console.log('x'.padEnd(4));
    //显示日期格式
    console.log('10'.padStart(2,0));
    console.log('1'.padStart(2,0));
  </script>
</body>
</html>